package com.bys.util;

import com.bys.response.Result;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.http.MediaType;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

public class RespUtils {
    public static void sendData(HttpServletResponse response,Result result) {
        try {
            response.setCharacterEncoding("UTF-8");
            response.setContentType(MediaType.APPLICATION_JSON_VALUE);
            PrintWriter writer = response.getWriter();
            writer.println(new ObjectMapper().writeValueAsString(result));
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
